<template>
    <div class="product-page">
        <PageHeader 
            title="产品展示" 
            subtitle="易凡科技创新产品与解决方案"
            :breadcrumbItems="[{ text: '首页', path: '/' }]"
            currentText="产品展示"
        />

        <!-- 产品分类选项卡 -->
        <div class="page-container">
            <div class="category-tabs">
                <el-tabs v-model="activeCategory" @tab-click="handleCategoryChange">
                    <el-tab-pane label="全部产品" name="all"></el-tab-pane>
                    <el-tab-pane v-for="category in categories" :key="category.id" :label="category.name" :name="category.id"></el-tab-pane>
                </el-tabs>
            </div>

            <!-- 产品列表 -->
            <div class="product-grid" v-loading="loading">
                <el-empty description="暂无产品" v-if="filteredProducts.length === 0 && !loading" />
                
                <div v-else class="product-list">
                    <div class="product-card" v-for="product in filteredProducts" :key="product._id" @click="viewProductDetail(product._id)">
                        <div class="product-image">
                            <img :src="product.cover || require('@/assets/images/product/红烧排骨.jpg')" :alt="product.title">
                            <div class="product-category">{{ getCategoryName(product.category) }}</div>
                        </div>
                        <div class="product-info">
                            <h3 class="product-title">{{ product.title }}</h3>
                            <p class="product-desc">{{ product.introduction || '暂无简介' }}</p>
                            <div class="product-footer">
                                <el-button type="primary" size="small" @click.stop="viewProductDetail(product._id)">查看详情</el-button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 推荐产品展示 -->
        <div class="featured-products" v-if="featuredProducts.length > 0">
            <div class="page-container">
                <div class="section-header">
                    <h2 class="section-title">推荐产品</h2>
                    <p class="section-desc">易凡科技精选解决方案</p>
                </div>
                
                <el-carousel :interval="4000" type="card" height="400px">
                    <el-carousel-item v-for="item in featuredProducts" :key="item._id">
                        <div class="featured-card" :style="{ backgroundImage: `url(${item.cover || require('@/assets/images/product/麻辣口水鸡.jpg')})` }">
                            <div class="overlay"></div>
                            <div class="featured-content">
                                <h3>{{ item.title }}</h3>
                                <p>{{ item.introduction }}</p>
                                <el-button type="primary" @click.stop="viewProductDetail(item._id)">了解详情</el-button>
                            </div>
                        </div>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </div>
    </div>

     <!-- 底部 -->
    <div class="footer">
        <div class="tiaozhuan">
            <ul>
                <li>易凡科技</li>
            </ul>
            <ul>
                <li class="lxwm">联系我们</li>
                <li>电话&nbsp;:&nbsp;087-32544554-322</li>
                <li>传真&nbsp;:&nbsp;097-245256549243</li>
                <li>邮箱&nbsp;:&nbsp;15593846869@163.com</li>
                <li>地址&nbsp;:&nbsp;甘肃省兰州市皋兰县海河街6号</li>
                <li>手机&nbsp;:&nbsp;15593846869</li>
                <li>公司&nbsp;:&nbsp;易凡科技</li>
                <li>合作伙伴&nbsp;:&nbsp;易凡TEAM科技有限公司</li>
                <li>社交媒体链接&nbsp;:&nbsp;http://localhost:8081</li>

            </ul>
            <ul>
                <li class="banquan">版权所有：易凡科技</li>
            </ul>
            <p><i
                    class="iconfont icon-icon-test12"></i>&nbsp;&nbsp;版权为易凡科技（中国）易凡TEAM有限公司所有，未经许可不得转载或链接，甘ICP备<span>62000002000103</span>号
            </p>
        </div>
    </div>

    <div class="zuifooter">
        <div>
            <p class="p1">|&nbsp;&nbsp;-甘ICP备<span>62000002000103</span>号-1-&nbsp;&nbsp;|</p>
            <p class="p2">本网站由易凡TEAM提供技术支持</p>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import PageHeader from '@/components/PageHeader.vue';

const router = useRouter();
const loading = ref(false);
const products = ref([]);
const featuredProducts = ref([]);
const activeCategory = ref('all');

// 产品分类
const categories = ref([
    { id: 'software', name: '软件产品' },
    { id: 'hardware', name: '硬件设备' },
    { id: 'solution', name: '解决方案' },
    { id: 'service', name: '技术服务' }
]);

// 根据分类筛选产品
const filteredProducts = computed(() => {
    if (activeCategory.value === 'all') {
        return products.value;
    }
    return products.value.filter(product => product.category === activeCategory.value);
});

// 获取分类名称
const getCategoryName = (categoryId) => {
    if (!categoryId) return '未分类';
    const category = categories.value.find(c => c.id === categoryId);
    return category ? category.name : '未分类';
};

// 处理分类变化
const handleCategoryChange = () => {
    console.log('切换到分类:', activeCategory.value);
};

// 查看产品详情
const viewProductDetail = (id) => {
    router.push(`/product/${id}`);
};

// 获取产品列表
const fetchProducts = async () => {
    loading.value = true;
    try {
        const res = await axios.get('/webapi/product/list');
        if (res.data && res.data.data) {
            products.value = res.data.data;
            // 选取前3个产品作为推荐产品
            featuredProducts.value = res.data.data.slice(0, 3);
        }
    } catch (error) {
        console.error('获取产品列表失败:', error);
    } finally {
        loading.value = false;
    }
};

onMounted(async () => {
    await fetchProducts();
});
</script>

<style lang="scss" scoped>
.product-page {
    padding-bottom: 60px;
    
    .category-tabs {
        margin-bottom: 30px;
    }
    
    .product-grid {
        min-height: 300px;
        margin-bottom: 40px;
    }
    
    .product-list {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 30px;
        
        @media (max-width: 1200px) {
            grid-template-columns: repeat(2, 1fr);
        }
        
        @media (max-width: 768px) {
            grid-template-columns: 1fr;
        }
    }
    
    .product-card {
        background: #fff;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        transition: transform 0.3s ease;
        cursor: pointer;
        
        &:hover {
            transform: translateY(-10px);
        }
        
        .product-image {
            height: 220px;
            overflow: hidden;
            position: relative;
            
            img {
                width: 100%;
                height: 100%;
                object-fit: cover;
                transition: transform 0.5s ease;
            }
            
            .product-category {
                position: absolute;
                top: 15px;
                right: 15px;
                background: rgba(0,0,0,0.6);
                color: #fff;
                padding: 4px 10px;
                border-radius: 20px;
                font-size: 12px;
            }
        }
        
        &:hover .product-image img {
            transform: scale(1.1);
        }
        
        .product-info {
            padding: 20px;
            
            .product-title {
                font-size: 18px;
                font-weight: 600;
                margin: 0 0 10px;
                color: #333;
            }
            
            .product-desc {
                color: #666;
                font-size: 14px;
                line-height: 1.5;
                margin-bottom: 15px;
                height: 60px;
                overflow: hidden;
                display: -webkit-box;
                -webkit-line-clamp: 3;
                -webkit-box-orient: vertical;
            }
            
            .product-footer {
                display: flex;
                justify-content: flex-end;
            }
        }
    }
    
    .featured-products {
        padding: 60px 0;
        background-color: #f9f9f9;
        
        .section-header {
            text-align: center;
            margin-bottom: 30px;
            
            .section-title {
                font-size: 28px;
                font-weight: 600;
                color: #333;
                margin-bottom: 10px;
            }
            
            .section-desc {
                color: #666;
                font-size: 16px;
            }
        }
        
        .featured-card {
            height: 100%;
            background-size: cover;
            background-position: center;
            border-radius: 8px;
            position: relative;
            overflow: hidden;
            
            .overlay {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: linear-gradient(to bottom, rgba(0,0,0,0.2), rgba(0,0,0,0.7));
            }
            
            .featured-content {
                position: absolute;
                bottom: 30px;
                left: 30px;
                right: 30px;
                color: #fff;
                
                h3 {
                    font-size: 24px;
                    font-weight: 600;
                    margin-bottom: 10px;
                }
                
                p {
                    font-size: 14px;
                    margin-bottom: 20px;
                    opacity: 0.9;
                }
            }
        }
    }
}

// 底部
* {
    margin: 0px;
    padding: 0px;
}

html,
body {
    height: 100%;
    min-height: 100vh;
    background: linear-gradient(45deg, #72d8e6, #00bcd4, #b9e06f, #efe372);
}

ul {
    list-style: none;
}
.footer {
    height: 415px;
    border-top: 2px solid #cccccc;
    background: rgb(76, 75, 75);
    margin-top: auto auto;
}

.footer ul:nth-child(1) li {
    font-size: 40px;
    margin-top: 0px;
    color: #b2bac4;
    height: 86px;
    line-height: 86px;
    display: block;
    width: 450px;
    padding-left: 10px;
    border-bottom: 2px solid #ecebeb;
}

.footer ul {
    height: 84px;
    padding-top: 0px;
    padding-left: 280px;
    padding-bottom: 30px;
    border-bottom: 1px solid #575656;
    line-height: 28px;
}

.footer ul li {
    width: 280px;
    padding-left: 30px;
    font-size: 15px;
    color: #b2bac4;
    float: left;
    /* word-wrap:normal; */
}

.footer .tiaozhuan .banquan {
    margin-top: 22px;
    margin-left: -430px;
}

.footer .tiaozhuan .iconfont {
    margin-left: -300px;
    margin-top: 0px;
}

.footer p {
    height: 61px;
    line-height: 61px;
    padding-left: 10px;
    font-size: 12px;
    margin-top: -75px;
    color: #9ba0a7;
}

.footer p span {
    color: #140eaf;
}

.zuifooter {
    height: 60px;
    margin-top: 30px;
    /* background:yellow; */
}

.zuifooter p {
    font-size: 13px;
    margin-left: 690px;
    display: block;
    width: 300px;
    color: #ababab;
}

.zuifooter p span {
    color: #ed4e26;
}

.footer ul:nth-child(3) {
    height: 50px;
}

.footer ul:nth-child(3) li {
    font-size: 16px;
    width: 996px;
    text-align: center;
}

.footer .tiaozhuan .lxwm {
    font-size: 30px;
    width: 100%;
    margin-bottom: 20px;
}

.footer i {
    font-size: 25px;
    height: 25px;
    width: 25px;
    text-align: center;
    line-height: 25px;
}
</style>